<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/global/jsp-header.jsp"%>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html">
		<title>新增部门</title>
		<%@ include file="/global/html-header.jsp"%>
		<script>
	$(function() {
		$('.myform').idealforms();
		common.validator("deptform");
		//添加部门
		$("#deptform").submit(function(){
			$("#deptId").removeAttr("disabled");
			var param=$(this).serialize();
			var canSubmit=common.checkBlankValue(param,new Array("dept.deptId","dept.deptName","dept.ability"));
			if(canSubmit){
				$.ajax({   
	        		type: "POST",  
	        		url: "${action }",  
	        		data: param, 
	        		success: function(msg){    
		        		window.parent.closeDialog();
		        		var alertMsg="";
	        			<c:if test="${addOperater}">
		        			if(msg=="success"){
	            				alertMsg="部门添加成功！";
	            				$(window.parent.document).find("#myform").submit();
	            			}else if(msg=="exists"){
	            				alertMsg="部门ID已存在！";
	            			}else{
	            				alertMsg="部门添加失败！";
	            			}
	        			</c:if>
	        			<c:if test="${updateOperater}">
		        			if(msg=="success"){
    	                    	var htm='<td>item.deptId</td><td>item.deptName</td><td>item.ability</td><td>'+
    	                    	'<a href="#" onclick="editDept(item.deptId)">编辑</a> <a href="#" onclick="deleteDept(item.deptId)">删除</a></td>';
    	                    	var dpId=common.getValueByFieldName(param,"dept.deptId");
    	                    	var dpName=common.getValueByFieldName(param,"dept.deptName");
    	                    	var dpAbility=common.getValueByFieldName(param,"dept.ability");
    	                    	htm=htm.replace(/item.deptId/gi,dpId).replace(/item.deptName/gi,decodeURI(dpName)).replace(/item.ability/gi,dpAbility);
    	                    	$(window.parent.document).find("#queryResultIframe").contents().find("tr[deptId="+dpId+"]").html(htm);
    	                    	$(window.parent.document).find("#queryResultIframe").contents().find("tr[deptId="+dpId+"]").attr("deptId",dpId);
    	                    	alertMsg="部门更新成功！";
	            			}else if(msg=="nochange"){
	            				alertMsg="部门属性没有改变！";
	            			}else{
	            				alertMsg="部门更新失败！";
	            			}
        				</c:if>
        				window.parent.editDeptTip(alertMsg);
	        		} 
	        	});
			}
			return false;
		});
	});
</script>
	</head>
	<body>
		<form action="${action }" name="deptform" class="myform"
			id="deptform" method="post">
		<div>
			<label class="required">
				部门编号:
			</label>
			<input type="text" size="40" id="deptId" name="dept.deptId" class="{required:true,digits:true,messages:{required:'请输入部门编号'}}" ${updateOperater ? 'disabled=true':''} value="${dept.deptId }"/>
		</div>
		<div>
			<label class="required">
				部门名称:
			</label>
			<input type="text" size="40" name="dept.deptName" class="{required:true,messages:{required:'请输入部门名称'}}" value="${dept.deptName }"/>
		</div>
		<div>
			<label class="required">
				部门职能:
			</label>
			<input type="text" size="40" name="dept.ability"
				class="{required:true,digits:true,messages:{required:'请输入部门职能'}}" value="${dept.ability }" />
		</div>
		<div>
			<label>
				&nbsp;
			</label>
			<input type="submit" value="${btnKeyWord }" />
		</div>
	</form>
	</body>
</html>